var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2EventsMgr = require("EventsMgr");
var $2FlbMathUtil = require("FlbMathUtil");
var $2DataManager = require("DataManager");
var $2Dfzd = require("Dfzd");
var $2JoyStick = require("JoyStick");
var $2UIManager = require("UIManager");
var $2FlbDateTimeUtil = require("FlbDateTimeUtil");
var $2UserDataManager = require("UserDataManager");
var $2AudioManager = require("AudioManager");
var $2KDefine = require("KDefine");
var $2pvzRecordVideoBt = require("pvzRecordVideoBt");
var $2pvzChannel = require("pvzChannel");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_JiujiudaifuUI = /* */function (_cc$Component31) {
  babel_inherits(C, _cc$Component31);
  var _super35 = babel_createSuper(C);
  function C() {
    var _this76;
    babel_classCallCheck(this, C);
    _this76 = _super35.apply(this, arguments);
    _this76.recordBt = null;
    _this76.rebornNode = null;
    _this76.endNode = null;
    _this76.player = null;
    _this76.joyStick = null;
    _this76.speed = 500;
    _this76.default_name = "";
    _this76.flag = false;
    _this76.dfzdrooms = null;
    _this76.dfzd_pref = null;
    _this76.djs_num = null;
    _this76.game_time = null;
    _this76.hps = null;
    _this76.hp1 = null;
    _this76.hp2 = null;
    _this76.hp3 = null;
    _this76.jjdf_end_pref = null;
    _this76.timeInfo = null;
    _this76.hbdian = null;
    _this76.curr_time = 0;
    _this76.total_time = 3;
    _this76.yx_time = 0;
    return _this76;
  }
  babel_createClass(C, [{
    key: "onLoad",
    value: function onLoad() {
      var _this77 = this;
      $2UIManager.default.instance.hideUI("MoneyPanelUI");
      this.joyStick = cc.find("joystick", this.node);
      this.dfzdrooms = cc.find("dfzdrooms", this.node);
      this.djs_num = cc.find("djs", this.node);
      this.game_time = cc.find("game_time", this.node);
      this.hps = cc.find("hps", this.node);
      this.hp1 = cc.find("hps/hp1/hp1", this.node);
      this.hp2 = cc.find("hps/hp2/hp1", this.node);
      this.hp3 = cc.find("hps/hp3/hp1", this.node);
      this.hbdian = cc.find("hbdian", this.node);
      $2EventsMgr.EventsManager.on("play_sp", function () {
        _this77.player && _this77.player.getComponent(sp.Skeleton).setAnimation(0, "run", true);
      });
      $2EventsMgr.EventsManager.on("game_over", function () {
        _this77.init();
      });
      $2EventsMgr.EventsManager.on("fuhuo", function () {
        _this77.fuhuo_init();
      });
      this.init();
      this.initPlatform();
    }
  }, {
    key: "onEnable",
    value: function onEnable() {
      $2AudioManager.default.instance.resumeBgm();
      $2UIManager.default.instance.hideUI("MoneyPanelUI");
      $2AudioManager.default.instance.playMusic($2KDefine.AudioName.bgm3, true);
      if ("tt" === $2pvzChannel.pvzChannel.instance().channel) {
        this.recordBt.show(this);
      } else {
        this.recordBt.node.active = false;
      }
    }
  }, {
    key: "showShareVideoWin",
    value: function showShareVideoWin() {
      if ("tt" === $2pvzChannel.pvzChannel.instance().channel) {
        if ($2pvzChannel.pvzChannel.instance().getRecordTime() < 15e3) {
          $2UIManager.default.instance.showToast("录屏失败，录屏时长需要大于15秒");
        } else {
          $2pvzChannel.pvzChannel.instance().shareVideo();
        }
      }
    }
  }, {
    key: "onDisable",
    value: function onDisable() {
      $2UIManager.default.instance.showUI("MoneyPanelUI");
    }
  }, {
    key: "initPlatform",
    value: function initPlatform() {
      $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p8") && $2pvzChannel.pvzChannel.instance().pauseAdTimeCount();
    }
  }, {
    key: "init",
    value: function init() {
      var _this78 = this;
      if (this.game_time) {
        $2UserDataManager.default.instance.getTimeInfo();
        this.player.getComponent(sp.Skeleton).setAnimation(0, "run", true);
        this.game_time.getComponent(cc.Label).string = $2FlbDateTimeUtil.FlbDateTimeUtil.sjformate(0);
        $2DataManager.default.instance.cur_hp = $2DataManager.default.instance.total_hp;
        this.djs_num.active = true;
        this.game_time.active = false;
        this.hp1.active = true;
        this.hp2.active = true;
        this.hp3.active = true;
        this.player.setPosition(0, -90);
        this.djs_num.setPosition(0, 115);
        this.joyStick.setPosition(this.hbdian.position);
        this.joyStick.getChildByName("stick").setPosition(cc.v2(0, 0));
        this.joyStick.getComponent($2JoyStick.default).dir = cc.v2(0, 0);
        for (var _e42 = 0; _e42 < this.dfzdrooms.childrenCount; _e42++) {
          this.dfzdrooms.children[_e42].removeAllChildren();
        }
        this.djs(function () {
          _this78.djs_num.active = false;
          $2DataManager.default.instance.is_over = false;
          $2DataManager.default.instance.yx_start_time = Date.now();
          _this78.game_time.active = true;
        });
        this.rebornNode.active = false;
        this.endNode.active = false;
        $2pvzChannel.pvzChannel.instance().recorderStart();
      }
    }
  }, {
    key: "fuhuo_init",
    value: function fuhuo_init() {
      var _this79 = this;
      if (this.game_time) {
        $2UserDataManager.default.instance.getTimeInfo();
        this.player.getComponent(sp.Skeleton).setAnimation(0, "run", true);
        $2DataManager.default.instance.cur_hp = $2DataManager.default.instance.total_hp;
        this.djs_num.active = true;
        this.game_time.active = false;
        this.hp1.active = true;
        this.hp2.active = true;
        this.hp3.active = true;
        this.player.setPosition(0, -90);
        this.djs_num.setPosition(0, 115);
        this.joyStick.setPosition(this.hbdian.position);
        this.joyStick.getChildByName("stick").setPosition(cc.v2(0, 0));
        this.joyStick.getComponent($2JoyStick.default).dir = cc.v2(0, 0);
        for (var _e43 = 0; _e43 < this.dfzdrooms.childrenCount; _e43++) {
          this.dfzdrooms.children[_e43].removeAllChildren();
        }
        this.djs(function () {
          _this79.djs_num.active = false;
          $2DataManager.default.instance.is_over = false;
          $2DataManager.default.instance.yx_start_time = Date.now() - 1e3 * $2DataManager.default.instance.offset_time;
          _this79.game_time.active = true;
        });
        this.rebornNode.active = false;
        this.endNode.active = false;
        $2pvzChannel.pvzChannel.instance().recorderStart();
      }
    }
  }, {
    key: "game_over",
    value: function game_over() {
      var _this80 = this;
      if (!($2DataManager.default.instance.cur_hp > 0)) {
        $2DataManager.default.instance.offset_time = this.yx_time;
        this.player.getComponent(sp.Skeleton).setAnimation(0, "die", false);
        $2DataManager.default.instance.is_over = true;
        this.unscheduleAllCallbacks();
        $2AudioManager.default.instance.playEffect($2KDefine.AudioName.jieshu);
        this.scheduleOnce(function () {
          if ($2DataManager.default.instance.fuhuo_flag) {
            _this80.rebornNode.active = false;
            _this80.endNode.active = true;
            $2DataManager.default.instance.fuhuo_flag = false;
          } else {
            _this80.rebornNode.active = true;
            _this80.endNode.active = false;
          }
        }, 1);
        $2pvzChannel.pvzChannel.instance().recorderStop();
      }
    }
  }, {
    key: "update_time",
    value: function update_time() {
      var e = Date.now();
      var t = Math.floor((e - $2DataManager.default.instance.yx_start_time) / 1e3);
      this.yx_time = t;
      this.game_time.getComponent(cc.Label).string = $2FlbDateTimeUtil.FlbDateTimeUtil.sjformate(t);
    }
  }, {
    key: "update_hp",
    value: function update_hp() {
      switch ($2DataManager.default.instance.cur_hp) {
        case 3:
          this.hp1.active = true;
          this.hp2.active = true;
          this.hp3.active = true;
          break;
        case 2:
          this.hp1.active = false;
          break;
        case 1:
          this.hp1.active = false;
          this.hp2.active = false;
          break;
        case 0:
          this.hp1.active = false;
          this.hp2.active = false;
          this.hp3.active = false;
          this.game_over();
      }
    }
  }, {
    key: "djs",
    value: function djs(e) {
      var _this81 = this;
      var t = 3;
      this.djs_num.getComponent(cc.Label).string = t + "";
      this.schedule(function () {
        if (t <= 0) {
          $2AudioManager.default.instance.playEffect($2KDefine.AudioName.djs2);
          return void (e && e());
        }
        _this81.djs_num.getComponent(cc.Label).string = t + "";
        t--;
        $2AudioManager.default.instance.playEffect($2KDefine.AudioName.djs1);
      }, 1, t, 0);
    }
  }, {
    key: "fire",
    value: function fire(e) {
      var t = Date.now();
      var a = Math.floor((t - $2DataManager.default.instance.yx_start_time) / 1e3);
      for (var _s9 = 0; _s9 < $2UserDataManager.default.instance.timeInfo.length; _s9++) {
        var _e44 = $2UserDataManager.default.instance.timeInfo[_s9];
        if (a < _e44.gametime) {
          this.timeInfo = _e44;
          break;
        }
      }
      this.total_time = $2FlbMathUtil.MathUtil.getRandom(this.timeInfo.skilltime[0], this.timeInfo.skilltime[1]);
      this.curr_time += e;
      if (this.curr_time < this.total_time) {
        return;
      }
      this.curr_time = 0;
      var n = [{
        name: "FX1",
        is_loop: true
      }, {
        name: "FX2_2",
        is_loop: true
      }, {
        name: "FX3",
        is_loop: false
      }, {
        name: "FX4_2",
        is_loop: true
      }, {
        name: "FX5",
        is_loop: true
      }, {
        name: "FX6",
        is_loop: true
      }, {
        name: "FX7",
        is_loop: true
      }, {
        name: "FX8",
        is_loop: true
      }, {
        name: "FX9_2",
        is_loop: true
      }, {
        name: "FX10",
        is_loop: false
      }, {
        name: "FX11",
        is_loop: true
      }];
      var i = [];
      for (var _s10 = 0; _s10 < this.timeInfo.count.length; _s10++) {
        i.push(this.timeInfo.count[_s10][1]);
      }
      var l = $2FlbMathUtil.MathUtil.getRand(i);
      var r = undefined;
      var c = undefined;
      for (var _o2 = 0; _o2 < this.timeInfo.count[l][0]; _o2++) {
        var _e45 = $2FlbMathUtil.MathUtil.getRandomInt(0, this.dfzdrooms.childrenCount - 1);
        var _t29 = $2FlbMathUtil.MathUtil.getRandomInt(0, n.length - 1);
        if (null != _e45) {
          var _t30 = Math.abs(_e45 - r);
          for (; _t30 < 2;) {
            _e45 = $2FlbMathUtil.MathUtil.getRandomInt(0, this.dfzdrooms.childrenCount - 1);
            _t30 = Math.abs(_e45 - r);
          }
        }
        if (null != (_t29 = $2FlbMathUtil.MathUtil.getRandomInt(0, n.length - 1))) {
          var _e46 = [2, 9, 10];
          for (; _e46.includes(_t29);) {
            _t29 = $2FlbMathUtil.MathUtil.getRandomInt(0, n.length - 1);
          }
        }
        r = _e45;
        c = _t29;
        this.createJfzd(_e45, _t29, n, this.timeInfo.speed);
      }
    }
  }, {
    key: "createJfzd",
    value: function createJfzd(e, t, a, n) {
      var i = cc.instantiate(this.dfzd_pref);
      i.parent = this.dfzdrooms.children[e];
      i.getComponent(sp.Skeleton).setAnimation(0, a[t].name, a[t].is_loop);
      i.getComponent($2Dfzd.default).setType(t, n);
    }
  }, {
    key: "update",
    value: function update(e) {
      if ($2DataManager.default.instance.is_over) {
        return;
      }
      this.update_hp();
      this.update_time();
      this.fire(e);
      if (this.joyStick.getComponent($2JoyStick.default).dir.mag() < .5) {
        return;
      }
      var t = this.joyStick.getComponent($2JoyStick.default).dir.x * this.speed * e;
      var a = this.joyStick.getComponent($2JoyStick.default).dir.y * this.speed * e;
      this.player.x += t;
      this.player.y += a;
      var n = Math.atan2(this.joyStick.getComponent($2JoyStick.default).dir.y, this.joyStick.getComponent($2JoyStick.default).dir.x);
      var i = cc.misc.radiansToDegrees(n);
      this.player.scaleX = i > 90 && i < 180 || i < -90 && i > -180 ? -.2 : .2;
      this.player.x > cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX && (this.player.x = cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX);
      this.player.x < -cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX && (this.player.x = -cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX);
      this.player.y > cc.winSize.height / 2 - this.player.height * this.player.scaleY && (this.player.y = cc.winSize.height / 2 - this.player.height * this.player.scaleY);
      this.player.y < -cc.winSize.height / 2 && (this.player.y = -cc.winSize.height / 2);
    }
  }]);
  return C;
}(cc.Component);
cc__decorate([ccp_property($2pvzRecordVideoBt.default)], def_JiujiudaifuUI.prototype, "recordBt", undefined);
cc__decorate([ccp_property(cc.Node)], def_JiujiudaifuUI.prototype, "rebornNode", undefined);
cc__decorate([ccp_property(cc.Node)], def_JiujiudaifuUI.prototype, "endNode", undefined);
cc__decorate([ccp_property(cc.Node)], def_JiujiudaifuUI.prototype, "player", undefined);
cc__decorate([ccp_property(cc.Prefab)], def_JiujiudaifuUI.prototype, "dfzd_pref", undefined);
cc__decorate([ccp_property(cc.Prefab)], def_JiujiudaifuUI.prototype, "jjdf_end_pref", undefined);
def_JiujiudaifuUI = cc__decorate([ccp_ccclass], def_JiujiudaifuUI);
exports.default = def_JiujiudaifuUI;